package 力扣算法练习.main1.newPart1;

public class day17 {
    //https://leetcode.cn/problems/UHnkqh/submissions/375247675/
    public class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }
    public ListNode reverseList(ListNode head) {
        //排除只有一个元素的情况
        if(head==null)return null;
        if (head.next == null) {
            return head;
        }
        ListNode sllow = head.next;
        ListNode fast = head.next.next;
        head.next = null;
        while(fast!=null){
            sllow.next=head;
            head=sllow;
            sllow=fast;
            fast=fast.next;
        }
        sllow.next=head;
        head=sllow;
        return head;
    }


}
